<div class="layui-fluid"  lay-title="内容编辑" id="app-vue">

    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form-item  layui-col-space10">
                    <div class="layui-inline nepadmin-mar-l10">
                        <el-button size="small" type="primary" :loading="submitLoading"  @click="handleSubmit({})">保存</el-button>
                    </div>

                </div>
                <div class="layui-card-body nepadmin-pad-l10 nepadmin-pad-r10">

                   <el-form ref="form" :model="temp" label-width="120px">
                       <el-form-item label="文件路径" prop="path">
                           <el-input v-model="temp.path"  readonly></el-input>
                       </el-form-item>
                       <el-form-item label="文件内容" prop="content">
                           <my-codemirror ref="myCodemirror" />
                       </el-form-item>
                   </el-form>

                </div>
            </div>
        </div>

    </div>

</div>
<script>
    layui.extend({

        'myCodemirror':"/views/components/myCodemirror"
    }).use(['admin','conf','jquery','view','myCodemirror'], function (admin,conf,$,view,myCodemirror) {
        var page_param = admin.route.search
        var path = (page_param.path||"").replaceAll("-","/")
        var app = new Vue({
            el: '#app-vue',
            data: {
                submitLoading:false,
                tableData:[],
                listQuery:{},
                temp:{
                    path:path,
                },
            },
            components:{
                'my-codemirror':myCodemirror
            },
            created:function() {
                this._initData()
            },
            methods: {
                _initData:function(){
                    let that = this
                    admin.post({
                        url:'/admin/web/fileContent'
                        ,data:{path:this.temp.path}
                        ,success: function (res) {
                            var data = res.data || {}
                            that.temp.content = data.content||""
                            that.$refs['myCodemirror'].setContent(data.content)
                        }
                        ,complete:function(){
                            console.log('complete')
                        }
                    })
                },
                handleSubmit:function(){
                    let that = this
                    that.submitLoading = true;
                    admin.post({
                        url:'/admin/web/fileContentSave'
                        ,data:{path:this.temp.path,content:that.$refs['myCodemirror'].getContent()}
                        ,success: function (res) {
                            var data = res.data || {}
                            that.$message.success(res.msg)
                        }
                        ,complete:function(){
                            that.submitLoading = false;
                            console.log('complete')
                        }
                    })
                },


            }
        })

    })
</script>